package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.MachineDeployTemplateService;
import com.yunhai.model.entity.dms.DmsMachineDeployTemplateEntity;
import com.yunhai.model.vo.dms.DmsMachineDeployTemplateQuery;
import com.yunhai.model.vo.dms.DmsMachineDeployTemplateVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/machineDeployTemplate")
public class MachineDeployTemplateController {

	@Resource
	private MachineDeployTemplateService machineDeployTemplateService;


	/**
	 * 获取 MachineDeployTemplate 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getMachineDeployTemplatePagination(PaginationVo paginationVo, DmsMachineDeployTemplateQuery dmsMachineDeployTemplateQuery ) throws Exception {
		IPage page = machineDeployTemplateService.getMachineDeployTemplatePagination(paginationVo, dmsMachineDeployTemplateQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 MachineDeployTemplate 所有数据
	 */
	@GetMapping("/allList")
	public Ret getMachineDeployTemplateAllList( DmsMachineDeployTemplateQuery dmsMachineDeployTemplateQuery ) throws Exception {
		List<DmsMachineDeployTemplateEntity> list = machineDeployTemplateService.getMachineDeployTemplateAllList( dmsMachineDeployTemplateQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 MachineDeployTemplate 详情
	 */
	@GetMapping("/{id}")
	public Ret getMachineDeployTemplateDetailById(@PathVariable Long id) throws Exception {

	    DmsMachineDeployTemplateEntity dmsMachineDeployTemplateEntity = machineDeployTemplateService.getMachineDeployTemplateDetail(id);
		return Ret.ok(dmsMachineDeployTemplateEntity);
	}


	/**
	 * 新增 MachineDeployTemplate
	 * */
	@PostMapping("")
	public Ret addMachineDeployTemplate(@RequestBody DmsMachineDeployTemplateVo dmsMachineDeployTemplateVo) throws Exception {

		machineDeployTemplateService.addMachineDeployTemplate(dmsMachineDeployTemplateVo);
		return Ret.ok();
	}


	/**
	 * 更新 MachineDeployTemplate
	 * */
	@PutMapping("")
	public Ret updateMachineDeployTemplate(@RequestBody DmsMachineDeployTemplateVo dmsMachineDeployTemplateVo) throws Exception {

		machineDeployTemplateService.updateMachineDeployTemplate(dmsMachineDeployTemplateVo);
		return Ret.ok();
	}


	/**
	 * 删除 MachineDeployTemplate
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveMachineDeployTemplate( @RequestBody List<Long> ids ) throws Exception {

	    machineDeployTemplateService.batchRemoveMachineDeployTemplate(ids);
		return Ret.ok();
	}
}
